package com.mk.legoscans2.tasks;

import android.os.AsyncTask;
import android.view.Menu;
import android.view.MenuItem;

import com.mk.legoscans2.LegoScans3Application;
import com.mk.legoscans2.R;
import com.mk.legoscans2.Scan;
import com.mk.legoscans2.actionbar.ActionBarHelper;

public class SetIsFavoriteTask extends AsyncTask<String, Void, Boolean>{

	Menu _menu;
	Scan _scan;
	ActionBarHelper _actionBarHelper;
	
	public SetIsFavoriteTask(Menu menu, Scan scan, ActionBarHelper actionBarHelper) {
		_menu = menu;
		_scan = scan;
		_actionBarHelper = actionBarHelper;
	}

	@Override
	protected Boolean doInBackground(String... params) {
		return LegoScans3Application.FavoritesService.isFavorite(_scan._scanId);
	}
	
	@Override
	protected void onPostExecute(Boolean result) {
		MenuItem menuItem = _menu.findItem(R.id.menu_favorite);
		menuItem.setEnabled(true);
		menuItem.setIcon(result ? R.drawable.btn_star_big_on_pressed : R.drawable.btn_star_big_off);
		_actionBarHelper.setFavoriteIcon(result);
	}
}